import {
	customer
} from '@/api/index.js'
import useUserStore from '@/store/user.js'
const useStore = useUserStore()

// 判断是否登录
export function useLogin(callBack) {
	 checkAudit().then(res => {
		callBack(true)
	})
}
// 判断是否报名
export function checkAudit() {
	const uid = useStore.uid
	let that = this
	return new Promise(async resolve => {
		customer.getRegisterAudit({
			userId: uid
		}).then((res) => {
			console.log('成功', res)
			if (res.code == 0) {
				const audit = res.data.audit
				if (audit == null) {
					uni.showModal({
						title: '温馨提示',
						content: '您还未参加报名，需报名审核通过后才能使用该功能，是否前往报名？',
						showCancel: false,
						success(res) {
							if (res.confirm) {
								// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
								uni.navigateTo({
									url: '/pages/registerInformation/index'
								  })
							}
						}
					});
				}
				if (audit == 0) {
					uni.showModal({
						title: '温馨提示',
						content: '需报名审核通过后才能使用该功能，请耐心等待',
						showCancel: false,
					});
				}
				if (audit == 1) {
					resolve(res)
				}
				if (audit == 2) {
					uni.showModal({
						title: '温馨提示提示',
						content: '您的报名审核未通过，需报名审核通过后才能使用该功能,是否前往重新报名?',
						success(res) {
							if (res.confirm) {
								uni.navigateTo({
									url: '/pages/registerInformation/index'
								  })
							}
						}
					});
				}
			} else {
				uni.showToast({
					title: '获取报名信息失败',
					icon: 'none',
					duration: 2000
				});
			}
		})
	})
}